package com.wxzz.elearing.evaluation.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.evaluation.dto.*;
import com.wxzz.elearing.evaluation.entity.*;
import com.wxzz.elearing.evaluation.service.IBusinessCategoryEvaluationService;
import com.wxzz.elearing.evaluation.service.IBusinessCategoryService;
import com.wxzz.elearing.evaluation.service.ITopicService;
import com.wxzz.elearing.evaluation.vo.BusinessCategoryTopicIsPassVo;
import com.wxzz.elearing.evaluation.vo.TopicVo;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/wx-topic")
@Api(tags = "测评题目接口(小程序)")
public class WxTopicController {

    @Autowired
    private ITopicService topicService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "展示工厂体检试题(小程序)", notes = "展示工厂体检试题(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "wxListTopic4factory", method = RequestMethod.POST)
    public ReturnVO<TopicVo> wxListTopic4factory(@RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return topicService.wxListTopic(0, jsonObject.getLong("id"));
    }

//    @ApiOperation(value = "展示星级认证试题(小程序)", notes = "展示星级认证试题(小程序)", httpMethod = "POST", tags = "小程序")
//    @RequestMapping(value = "wxListTopic4start", method = RequestMethod.POST)
//    public ReturnVO<TopicVo> wxListTopic4start(@RequestHeader String token) {
//        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
//        return topicService.wxListTopic(1, jsonObject.getLong("id"));
//    }

    @ApiOperation(value = "展示能力测评项目(小程序)", notes = "展示能力测评项目(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listBusinessCategoryEvaluation", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryEvaluation>>> listBusinessCategoryEvaluation(@RequestHeader String token, @RequestBody WxBusinessCategoryEvaluationDto wxBusinessCategoryEvaluationDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return topicService.listBusinessCategoryEvaluation(jsonObject.getLong("id"), wxBusinessCategoryEvaluationDto);
    }

    @ApiOperation(value = "展示星级认证测评试题(小程序)", notes = "展示星级认证测评试题(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "wxListTopic4start/{businessCategoryEvaluationId}", method = RequestMethod.POST)
    public ReturnVO<TopicVo> wxListTopic4start(@RequestHeader String token, @PathVariable Long businessCategoryEvaluationId) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return topicService.wxListTopic4evaluation(jsonObject.getLong("id"), 1,businessCategoryEvaluationId);
    }

    @ApiOperation(value = "展示能力测评试题(小程序)", notes = "展示能力测评试题(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "wxListTopic4evaluation/{businessCategoryEvaluationId}", method = RequestMethod.POST)
    public ReturnVO<TopicVo> wxListTopic4evaluation(@RequestHeader String token, @PathVariable Long businessCategoryEvaluationId) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return topicService.wxListTopic4evaluation(jsonObject.getLong("id"), 2,businessCategoryEvaluationId);
    }

    @Autowired
    private IBusinessCategoryEvaluationService businessCategoryEvaluationService;

    @ApiOperation(value = "根据测评id查询详情(小程序)", notes = "根据测评id查询详情(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectBusinessCategoryEvaluationDetailById/{businessCategoryEvaluationId}", method = RequestMethod.POST)
    public ReturnVO<BusinessCategoryEvaluation> selectBusinessCategoryEvaluationDetailById(@RequestHeader String token,@PathVariable Long businessCategoryEvaluationId) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryEvaluationService.selectBusinessCategoryEvaluationDetailById(jsonObject.getLong("enterpriseId"),jsonObject.getLong("id"),businessCategoryEvaluationId);
    }

    @ApiOperation(value = "测评数据(学习报告)(小程序)", notes = "测评数据(学习报告)(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectByEvaluationDataDto", method = RequestMethod.POST)
    public ReturnVO<EvaluationDataDto> selectByEvaluationDataDto(@RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryEvaluationService.selectByEvaluationDataDto(jsonObject.getLong("enterpriseId"));
    }

    @ApiOperation(value = "保存草稿箱(小程序)", notes = "保存草稿箱(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "saveTopicMongoDto", method = RequestMethod.POST)
    public ReturnVO saveTopicMongoDto(@RequestHeader String token,@Valid @RequestBody TopicMongoDto topicMongoDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        topicMongoDto.setWxUserId(jsonObject.getLong("id"));
        return topicService.saveTopicMongoDto(topicMongoDto);
    }

    @ApiOperation(value = "查询草稿箱列表(小程序)", notes = "查询草稿箱列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listTopicMongoDto", method = RequestMethod.POST)
    public ReturnVO<List<TopicMongoDto>> listTopicMongoDto(@RequestHeader String token,@Valid @RequestBody TopicMongoSelDto topicMongoSelDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return topicService.listTopicMongoDto(jsonObject.getLong("id"), topicMongoSelDto);
    }

    @ApiOperation(value = "查询草稿箱详情(小程序)", notes = "查询草稿箱详情(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectTopicMongoDtoByUid/{uid}", method = RequestMethod.POST)
    public ReturnVO<TopicMongoDto> selectTopicMongoDtoByUid(@PathVariable String uid) {
        return topicService.selectTopicMongoDtoByUid(uid);
    }


    @ApiOperation(value = "工厂体检/星级认证/能力测评测试结束调用(小程序)", notes = "工厂体检/星级认证/能力测评测试结束调用(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "businessCategoryTopicIsPass", method = RequestMethod.POST)
    public ReturnVO businessCategoryTopicIsPass(@RequestHeader String token,@RequestBody BusinessCategoryTopicIsPassDto businessCategoryTopicIsPassDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return topicService.businessCategoryTopicIsPass(jsonObject,businessCategoryTopicIsPassDto);
    }

    @ApiOperation(value = "查询能力测评结果(小程序)", notes = "查询能力测评结果(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectBusinessCategoryEvaluationHistoryById/{businessCategoryEvaluationHistoryId}", method = RequestMethod.POST)
    public ReturnVO<BusinessCategoryEvaluationHistory> selectBusinessCategoryEvaluationHistoryById(@PathVariable Long businessCategoryEvaluationHistoryId) {
        return topicService.selectBusinessCategoryEvaluationHistoryById(businessCategoryEvaluationHistoryId);
    }

    @ApiOperation(value = "查询工厂体检/星级认证测评结果 0-工厂体检 1-星级认证(小程序)", notes = "查询工厂体检/星级认证测评结果 0-工厂体检 1-星级认证(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectBusinessCategoryRuleHistoryById/{businessCategoryRuleHistoryId}/{type}", method = RequestMethod.POST)
    public ReturnVO<BusinessCategoryRuleHistory> selectBusinessCategoryRuleHistoryById(@PathVariable Long businessCategoryRuleHistoryId, @PathVariable Integer type) {
        return topicService.selectBusinessCategoryRuleHistoryById(businessCategoryRuleHistoryId,type);
    }

    @Autowired
    private IBusinessCategoryService businessCategoryService;

    @ApiOperation(value = "根据当前用户列出测评标准(小程序)", notes = "根据当前用户列出测评标准(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "wxListEvaluationCriterion", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<EvaluationCriterion>>> wxListEvaluationCriterion(@RequestHeader String token, @Valid @RequestBody EvaluationCriterionDto evaluationCriterionDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryService.wxListEvaluationCriterion(jsonObject.getLong("id"), evaluationCriterionDto);
    }


}
